/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-04 09:50:21
 * @LastEditTime : 2023-07-20 14:47:42
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\FirstLevel\Form.jsx
 * @Description  :
 */
import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import {
    AddDataButton,
    ModDataButton,
    DelDataButton,
    OpenTwoRouter,
    CommonButton,
    ExamineButton,
} from '../Common/options'
import { Flow } from '../Common/Conversion'

export const Form = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        pageSize: 10,
        params: {
            pageIndex: 1,
            // flowUuid: 'b8138511-798e-41fe-b0b0-abff3abfe3f3'
        },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        hideInSearch: true,
        initialValues: { approvalStatus: 0 },
        options: [<AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.tableName, title: '标题' },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            {
                dataIndex: 'approvalStatus',
                title: '状态',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'infoContent',
                title: '内容',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'eventDate',
                title: '事件日期',
                valueType: 'Date',
                showTime: true,
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'flowUuid',
                title: '流程Uuid',
                rules: true,
                valueType: 'select',
                ellipsis: true,
                width: 100,
                valueEnum: await Flow(),
            },
            {
                dataIndex: 'approvalCondition',
                title: '金额',
                valueType: 'input',
                pattern: '[0-9]*',
                tooltip: '如果审批类型不是是“按表单中金额审批”,则审批填0。由配置人员填写数据,都是小于等',
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'approvalStatus',
                title: '状态',
                valueType: 'select',
                valueEnum: BuiltInData.FormApprovalStatus,
                hideInAdded: true,
                hideInModify: true,
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 600,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, approvalStatus } = record
                    return [
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />,
                        <OpenTwoRouter
                            key="TwoOne"
                            title="表单明细"
                            twoTitle="表单明细"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'Form',
                                Permission,
                                oneData: record,
                                header: data.columns,
                                ClientData,
                            }}
                        />,
                        <OpenTwoRouter
                            key="TwoTwo"
                            title="接收人员"
                            twoTitle="流程接收人员列表"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'FormConsigneeRecord',
                                Permission,
                                oneData: record,
                                header: data.columns,
                                ClientData,
                            }}
                        />,
                        approvalStatus === 0 && (
                            <CommonButton
                                key="submit"
                                OptionsEvent={OptionsEvent}
                                title="提交表单"
                                data={{ type: 'FlowFormSubmitModal', record, width: 1000, actionRef }}
                            />
                        ),
                        approvalStatus === 0 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),

                        approvalStatus !== 0 && (
                            <CommonButton
                                key="one"
                                OptionsEvent={OptionsEvent}
                                title="审批流程"
                                data={{ type: 'FlowChartDetail', record, width: 1000, actionRef }}
                            />
                        ),

                        approvalStatus !== 0 && (
                            <CommonButton
                                key="two"
                                OptionsEvent={OptionsEvent}
                                title="审批记录 "
                                data={{ type: 'FlowChartRecords', record, width: 1000, actionRef }}
                            />
                        ),

                        <CommonButton
                            key="thr"
                            OptionsEvent={OptionsEvent}
                            title="审批"
                            smallTile="审批流程操作"
                            data={{ type: 'FlowChartApprovalStatus', record, width: 1000, actionRef }}
                        />,

                        // <ExamineButton
                        //     key="thr"
                        //     title="审核"
                        //     data={{
                        //         actionRef,
                        //         OptionsEvent,
                        //         url: 'posSuperviseApproval',
                        //         smallTitle: '监理工序',
                        //     }}
                        //     options={[
                        //         { title: '合格', type: 'primary', emit: { path: [uuid, 2] } },
                        //         { title: '不合格', type: 'link', danger: true, emit: { path: [uuid, 3] } },
                        //     ]}
                        // />,

                        // <ExamineButton
                        //     key="fou"
                        //     title="不合格"
                        //     danger={true}
                        //     data={{
                        //         actionRef,
                        //         OptionsEvent,
                        //         url: 'posSuperviseApproval',
                        //         smallTitle: '监理工序',
                        //     }}
                        //     options={[
                        //         { title: '不合格', type: 'primary', emit: { path: [uuid, 3] } },
                        //         { title: '取消', type: 'link', emit: 'off' },
                        //     ]}
                        // />

                        // 动态添加审批人
                        // 打印审批单
                    ]
                },
            },
        ],
    }

    return data
}
